<template>
  <view class="content">
    <uni-nav-bar v-if="!isApp" left-icon="back" title="收益明细" shadow="false" @click-left="back()" :fixed="true"></uni-nav-bar>
    <view class="profitList" :style="{ 'padding-top': isApp ? '0' : '88upx' }">
      <view class="bg"></view>
      <scroll-view class="profitList_main" scroll-y :style="{ 'top': isApp ? '20upx' : '108upx' }" @scrolltolower="load">
        <view style="padding: 0 50upx;">
          <view class="item clear" v-for="(item,index) in list" :key="index">
            <view class="fl">
              <text style="color: #000000;">{{Text(item)}}</text>
              <text style="color: #666666; font-size: 22upx;">{{$formta(item.updateTime,'yyyy-MM-dd hh:mm')}}</text>
            </view>
            <view class="fr">
              <view>+{{item.allotProfit}}</view>
              <view style="font-size: 22upx;">
                <text style="color: #ff0000;" v-if="">{{item.allotStatus == 'INIT' ? '已分配，未领取' : '已领取'}}</text>
              </view>
            </view>
          </view>
        </view>
        <uni-load-more :status="loading ? 'loading' : noData ? 'noMore' : 'noMore'"></uni-load-more>
      </scroll-view>
      <HMmessages ref="HMmessages" @complete="HMmessages = $refs.HMmessages" @clickMessage="clickMessage"></HMmessages>
    </view>
  </view>
</template>

<script>
import uniNavBar from '@/components/uni-nav-bar/uni-nav-bar.vue';
import service from '../service.js';
import { uniLoadMore } from '@dcloudio/uni-ui';
import HMmessages from '@/components/HM-messages/HM-messages.vue';
export default {
  components: { uniNavBar,HMmessages,uniLoadMore },
  data() {
    return {
      isApp: uni.getStorageSync('isAppH5'),
      list:[],
      pageNo:1,
      pageSize:10,
      loading:true,
      noData:false,
    };
  },
  onShow() {
    this.list = [];
    this.noData = false;
    this.pageNo =1;
    this.getProfit();
  },
  methods:{
    //返回文字
    Text(item){
      if(item.profitType == 'SIGNUP'){
        return '转入-早起打卡'
      }else if(item.profitType == 'INVITE'){
        return '转入-邀请奖励'
      }
    },
    //加载更多
    load() {
      if (this.loading) {
        return false;
      }
      if (this.noData) {
        return false;
      }
      this.pageNo++;
      this.loading = true;
      this.getProfit();
    },
    //获取记录
    getProfit(){
      this.loading = true;
      service.getProfit({
        pageNo:this.pageNo,
        pageSize:this.pageSize
      }).then(({data})=>{
        this.loading = false;
        if (data.code == '100200') {
          this.list = this.list.concat(data.data.records);
          if (data.data.pages == 1 || data.data.pages == 0) {
            this.noData = true;
            return false;
          }
          if (this.pageNo >= data.data.pages) {
            this.noData = true;
          } else {
            this.noData = false;
          }
        } else {
          this.pageNo--;
          this.errors(data.msg);
        }
      })
    },
    //修改手机返回
    back() {
      let length = getCurrentPages();
      if (length.length == 1) {
        uni.switchTab({
          url: '../../index/index'
        });
      } else {
        uni.navigateBack();
      }
    },
    //错误提示
    errors(text) {
      this.HMmessages.show(text, {
        textAlign: 'center',
        background: '#74272d',
        fontColor: '#fff'
      });
    }
  }
};
</script>

<style lang="scss">
@import './style.scss';
</style>
